package com.qf.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.constans.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;


@JsonInclude(JsonInclude.Include.NON_EMPTY)
@ApiModel(description = "统一的结果对象")
public class R {
    @ApiModelProperty(value = "状态码,具体参考状态码列表")
    private int code;//状态码,通过状态码可以快速的识别出是什么结果,相同的状态不管在什么接口中应该使用同一个状态码
    @ApiModelProperty(value = "状态码对应的描述")
    private String msg;//针对状态码的提示

    @ApiModelProperty(value = "真正返回的结果",example ="[{\"id\":1,\"areaname\":\"西城区\",\"parentid\":null,\"status\":1},{\"id\":2,\"areaname\":\"城关街道\",\"parentid\":null,\"status\":1},{\"id\":5,\"areaname\":\"冶源镇\",\"parentid\":null,\"status\":1},{\"id\":6,\"areaname\":\"二七区\",\"parentid\":null,\"status\":1},{\"id\":8,\"areaname\":\"雁塔区\",\"parentid\":null,\"status\":1}]" )
    private Object result;


    public static R setOk(Object result) {
//        R r = new R();
//        r.setCode(ResultCode.SUCCESS);
//        r.setMsg("成功");
//        r.setResult(result);
//        return r;
        return setError(ResultCode.SUCCESS, "成功", result);
    }


    public static R setError(Object result) {
//        R r = new R();
//        r.setCode(ResultCode.FAIL);
//        r.setMsg("网络异常,请检查您的网络");
//        r.setResult(result);
        return setError(ResultCode.FAIL, "网络异常,请检查您的网络", result);
    }

    public static R setError(int code,String msg,Object result) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setResult(result);
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }
}
